import java.util.Random;
import java.util.Scanner;

public class WuziQi {
    private static final String[] options = {"石头", "剪刀", "布"};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        while (true) {
            System.out.println("请输入你的选择（石头、剪刀、布），或输入“退出”结束游戏：");
            String userInput = scanner.nextLine().trim();
            if (userInput.equals("退出")) {
                System.out.println("感谢你的参与！再见！");
                break;
            }

            if (!isValidChoice(userInput)) {
                System.out.println("无效的输入，请输入石头、剪刀或布。");
                continue;
            }

            int computerChoice = random.nextInt(3);
            String computerInput = options[computerChoice];
            System.out.println("计算机选择: " + computerInput);

            String result = determineWinner(userInput, computerInput);
            System.out.println(result);
        }

        scanner.close();
    }

    private static boolean isValidChoice(String choice) {
        return "石头".equals(choice) || "剪刀".equals(choice) || "布".equals(choice);
    }

    private static String determineWinner(String user, String computer) {
        if (user.equals(computer)) {
            return "平局！";
        } else if ((user.equals("石头") && computer.equals("剪刀")) ||
                (user.equals("剪刀") && computer.equals("布")) ||
                (user.equals("布") && computer.equals("石头"))) {
            return "你赢了！";
        } else {
            return "你输了！";
        }
    }
}